from django.http import JsonResponse
from django.views import View
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator


class DashboardData(View):
    def get(self, request):
        return JsonResponse(
            {
                "metrics": {"flowchart": 0, "block": 0, "testcase": 0, "task": 0},
                "charts": {
                    "pass_rate": 0,
                    "completion_rate": 0,
                    "case_distribution": 0,
                },
                "tasks": {
                    "dates": [
                        "02-18",
                        "02-19",
                        "02-20",
                        "02-21",
                        "02-22",
                        "02-23",
                        "02-24",
                    ],
                    "counts": [0, 0, 0, 0, 0, 0, 0],
                    "status": {
                        "completed": 0,
                        "executing": 0,
                        "pending": 0,
                        "cancelled": 0,
                        "aborted": 0,
                    },
                },
            }
        )


@method_decorator(login_required, name="dispatch")
class ProductDashboardView(View):
    def get(self, request, product_id):
        # 获取产品详情逻辑
        product = request.user.products.get(id=product_id)
        return JsonResponse(
            {"id": product.id, "name": product.name, "dashboard_data": {}}  # 实际返回仪表盘数据
        )


def get_product_dashboard(request, product_id):
    return JsonResponse(
        {"id": "001", "name": "test", "dashboard_data": {}}  # 实际返回仪表盘数据
    )
